<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
	String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String dept_id = request.getParameter("dept_id") == null ? "" : request.getParameter("dept_id");
	String dept_name = request.getParameter("dept_name") == null ? "" : request.getParameter("dept_name");
	String gd_code = request.getParameter("gd_code") == null ? "" : request.getParameter("gd_code");
	String gd_name = request.getParameter("gd_name") == null ? "" : request.getParameter("gd_name");
%>
<html>
	<head>
		<title>甲供领料</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#table").datagrid({
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/gd/listPageGDSelfRequest?gd_id=<%=gd_id%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true}
				]],
				columns:[[
					{title:'申请日期',field:'operation_date',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:150,align:'center'},
					{title:'申请部门',field:'dept_name',width:100,align:'center'},
					{title:'申请人',field:'person',width:100,align:'center'},
					{title:'摘要',field:'remark',width:200,align:'center'},
					{title:'当前状态',field:'status',hidden:true},
					{title:'当前状态',field:'status_desc',width:100,align:'center'},
					{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
	                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditGDSelfRequest(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteGDMaterialRequest('"+rowData.id+"');\"/>&nbsp;&nbsp;"
	                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi('"+rowData.id+"');\"/>";
						}
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
							return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditGDSelfRequest(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
							      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi('"+rowData.id+"');\"/>";
						}
                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditGDSelfRequest(2,'"+rowData.id+"');\"/>";
	
					}}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var request_id = row.id;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'明细',
						url:'<%=contextPath %>/springMVC/gd/listGDSelfRequestDetail?request_id='+request_id,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'产品编号',field:'code',width:150,align:'center'},
							{title:'产品名称',field:'name',width:300,align:'center'},
							{title:'规格/型号',field:'format_type',width:200,align:'center'},
							{title:'单位',field:'unit_name',width:100,align:'center'},
							{title:'申请数量',field:'num',width:100,align:'center'},
							{title:'要求到货时间',field:'request_time',width:200,align:'center'},
							{title:'收货人',field:'receiver',width:200,align:'center'},
							{title:'联系电话',field:'phone',width:200,align:'center'},
							{title:'备注',field:'remark',width:300,align:'center'}
						]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				toolbar:
				[{
						id:'add',
						text:'添加',
						iconCls:"icon-add",
						handler:function(){
							addOrEditGDSelfRequest(0);
						}
					}
				],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		
		function addOrEditGDSelfRequest(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditJaRequest.jsp.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>",1000, 800);
			}else if(type==1){
				openDialogResize('<%=contextPath %>/springViews/gd/addOrEditJaRequest.jsp.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&id='+id,1000, 800);
			}else{
				openDialogResize('<%=contextPath %>/springViews/gd/addOrEditJaRequest.jsp.jsp?isShow=1&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&id='+id,1000, 800);	
			}
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function deleteGDMaterialRequest(request_id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteSelfRequest",
						data:"request_id="+request_id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
	</script>
	<body>
		<div id="table" data-options="fit:true" ></div>
	</body>
</html>
